let config = require('./utils/config');
let functions = require('./utils/functions');
let api = require('./utils/api');
let data = require('./data/data.js');
console.info(data);
App({
    // 测试数据
    data:data,
    config,
    api,
    cache: {},
    functions,
    company:'芒果小店',//小程序
    videoId:'',//播放id
    videoContext:[],//播放方法
    cartNumber:0,//购物车数量
    cart:[],//购物车数据
    // 配色主题
    theme:{
        barText:"#ffffff",//文字颜色
        Background:"#F24900",//导航背景色
        specially:"#F24900",//主题色
        costar:"#eeb174",//配色
    },
    globalData: {
        windowWidth: 0,
        windowHeight: 0,
        is_iphoneX: false,
        is_ios: false,
    },
    onLaunch: function (cb) {
        console.info(this);
        this.is_iphoneX();
        this.getwindow();
    },
    onShow: function () {
    },
    onHide: function () {
    },
    //判断是否为iphonex
    is_iphoneX() {
        wx.getSystemInfo({
            success: res => {
                if (res.model.indexOf('iPhone X') != -1) {
                    this.globalData.is_iphoneX = true
                }
                if (res.system.indexOf('iOS') != -1) {
                    this.globalData.is_ios = true
                }
            }
        })
    },
    updateManager() {
        if (wx.canIUse('getUpdateManager')) {
            const updateManager = wx.getUpdateManager();
            updateManager.onCheckForUpdate(function (res) {
            })
            updateManager.onUpdateReady(function () {
                wx.showModal({
                    title: '更新提示',
                    content: '新版本已经准备好，是否重启应用？',
                    success(res) {
                        if (res.confirm) {
                            updateManager.applyUpdate()
                        }
                    }
                })
            })
            updateManager.onUpdateFailed(function () {
                console.log('新版本下载失败')
            })
        } else {
            wx.showModal({
                title: '提示',
                content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
            })
        }
    },
    // 获取当前屏幕可视区域
    getwindow() {
        let that = this;
        wx.getSystemInfo({
            success: function (res) {
                that.globalData.windowWidth = res.windowWidth;
                that.globalData.windowHeight = res.windowHeight;
            },
        })
    },
    // 用来推送信息
    postFormId(id) {
        let params = {
            form_id: id,
            openid: wx.getStorageSync('openid')
        }
        saveFormId(
            params,
            function (response) {

            },
            function (e) {

            }
        );
    },
    // 修改购物车数量
    UpdateCart() {
        let num = 0;
        if (this.cartNumber > 0) {
            num = this.cartNumber;
        }
        if (num == 0) {
            wx.removeTabBarBadge({
            index: 2,
            })
        } else {
            wx.setTabBarBadge({
            index: 2,
            text: String(num)
            })
        };
    },
    // 共享页面数据管理
    cache_add(pageModel) {
        let pagePath = pageModel.__route__;
        this.cache[pagePath] = pageModel;
    },
    cache_get(pageModel) {
        let pagePath = pageModel.__route__;
        return this.cache[pagePath];
    },
    cache_off(pageModel) {
        let pagePath = pageModel.__route__;
        try {
            delete this.cache[pagePath];
        } catch (e) {

        }
    }
});
